Allow customizing unique ID generation#1
Conversation
5cb9cd0 to
054367a
Compare
PR SummaryMedium Risk Overview Updates exports to expose the new setter, and refreshes Written by Cursor Bugbot for commit 054367a. This will update automatically on new commits. Configure here. |
|
Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.
Or push these changes by commenting: Preview (e484e66c7a)diff --git a/packages/utils/api-report.api.md b/packages/utils/api-report.api.md
--- a/packages/utils/api-report.api.md
+++ b/packages/utils/api-report.api.md
@@ -408,7 +408,7 @@
}>;
export { Required_2 as Required }
-// @internal
+// @public
export function restoreUniqueId(): void;
// @public
@@ -448,6 +448,9 @@
// @internal
export function setInSessionStorage(key: string, value: string): void;
+// @public
+export function setUniqueIdGenerator(fn: (size?: number) => string): void;
+
// @internal
export function sleep(ms: number): Promise<void>;
diff --git a/packages/utils/src/lib/id.ts b/packages/utils/src/lib/id.ts
--- a/packages/utils/src/lib/id.ts
+++ b/packages/utils/src/lib/id.ts
@@ -105,7 +105,7 @@
* @internal
*/
export function mockUniqueId(fn: (size?: number) => string) {
- impl = fn
+ setUniqueIdGenerator(fn)
}
/** |
|
oops, this has a build error. I'll revert my change and please fix build error. |

This let's app customize the algorithm that sets IDs, could be used to align ID generation between shapes & artifacts
Note
Introduces
setUniqueIdGeneratorto override ID generation globally and adds detailed docs/examples forcreateShapeId.@tldraw/utils):setUniqueIdGeneratorto override the global unique ID generator; keepuniqueIddelegating to the pluggable impl.restoreUniqueIdas public for reverting to the default generator.setUniqueIdGeneratorfrompackages/utils/src/index.ts.tlschema):createShapeIdwith examples and note about customizing viasetUniqueIdGenerator.Written by Cursor Bugbot for commit 5cb9cd0. This will update automatically on new commits. Configure here.